package constant.milk.cashbook.asset.credit;

import constant.milk.cashbook.R;
import constant.milk.cashbook.SuperActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;

public class AutoynActivity extends SuperActivity
{
	public static final String AUTOYN_DATA = "AUTOYN_DATA";

	private View autoYesView;
	private View autoNoView;
	
	private RadioButton autoYesRadio;
	private RadioButton autoNoRadio;
	
	private Button checkButton;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.autoyn_activity);
		
		setGoneTipButton();
		
		setTitle("자동유무");
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		autoYesView = findViewById(R.id.autoYesView);
		autoNoView = findViewById(R.id.autoNoView);
		
		autoYesRadio = (RadioButton) findViewById(R.id.autoYesRadio);
		autoNoRadio = (RadioButton) findViewById(R.id.autoNoRadio);
		
		checkButton = (Button) findViewById(R.id.checkButton);
	}

	@Override
	protected void setOnClick()
	{
		autoYesView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setOkChecked();
			}
		});
		
		autoNoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setNoChecked();
			}
		});
		
		checkButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent();
				
				if (autoNoRadio.isChecked())
				{
					intent.putExtra(AUTOYN_DATA, getResources().getString(R.string.autoNo));
				}
				else
				{
					intent.putExtra(AUTOYN_DATA, getResources().getString(R.string.autoYes));
				}
				
				setResult(Activity.RESULT_OK, intent);
				finish();
			}
		});
	}

	@Override
	protected void setData()
	{
		Intent intent = getIntent();
		String flag = intent.getStringExtra(AUTOYN_DATA);
		
		if (flag.equals(getResources().getString(R.string.autoNo)))
		{
			setNoChecked();
		}
		else
		{
			setOkChecked();
		}
	}
	
	private void setOkChecked()
	{
		autoYesRadio.setChecked(true);
		autoNoRadio.setChecked(false);
	}
	
	private void setNoChecked()
	{
		autoYesRadio.setChecked(false);
		autoNoRadio.setChecked(true);
	}

	@Override
	protected void tipButton()
	{
	}

}
